package com.xyh.eduservice.controller;


import com.xyh.commonutils.R;
import com.xyh.eduservice.entity.subject.OneSubject;
import com.xyh.eduservice.service.EduSubjectService;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-08-07
 */
@RestController
@RequestMapping("/eduservice/subject")
//@CrossOrigin  //跨域
public class EduSubjectController {

    @Resource
    private EduSubjectService subjectService;

    //添加课程分类
    //获取上传过来文件，把文件内容读取出来
    @PostMapping("/addSubject")
    public R addSubject(MultipartFile file){
        //上传过来 excel 文件
        subjectService.saveSubject(file,subjectService);
        return R.ok();
    }

    //课程分类列表(树形)
    @GetMapping("/getAllSubject")
    public R getAllSubject(){
        //list 集合泛型是一级分类 ，一级分类中又有二级分类
        List<OneSubject> list = subjectService.getAllOneTwoSubject();
        return R.ok().data("list",list);
    }
}

